package net.tv90.bfmccore.squad;

import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;

import java.util.List;

import static net.tv90.bfmccore.squad.Squad.squadMap;

public class SquadPapiShow extends PlaceholderExpansion {

    /**
     * 这是papi变量的前缀squad_
     *
     * @return 前缀
     */
    @Override
    public String getIdentifier() {
        return "squad";
    }

    @Override
    public String getVersion() {
        return "1.0.0";
    }

    @Override
    public String getAuthor() {
        return "TV90";
    }

    /**
     * 根据papi变量字段返回玩家在游戏中看到的内容
     *
     * @param player 玩家
     * @param params papi变量字段 show_0~5_RU/CN/US
     * @return 玩家看到的信息
     */
    @Override
    public String onRequest(OfflinePlayer player, String params) {
        if (params.startsWith("show_")) {
            String index = params.split("_")[1];
            if (player instanceof Player) {
                String country = params.split("_")[2];
                if (!country.equals("RU") && !country.equals("CN") && !country.equals("US")) {
                    return "无小队";
                }
                List<String> list = squadMap.get(country + "_Squad_" + index);
                if (list == null || list.isEmpty()) {
                    return "§e小队人数: §a[0/" + Squad.SQUAD_MAX_SIZE + "]\n" + "§e小队长:\n§c无队长\n" + "§e小队玩家:\n§a无队员";
                } else {
                    StringBuilder sb = new StringBuilder();
                    for (int i = 1; i < list.size(); i++) {
                        sb.append(list.get(i)).append('/');
                    }
                    String member = sb.toString();
                    if (list.size() == 1) member = "无队员";
                    return "§e小队人数: §a[" + list.size() + "/" + Squad.SQUAD_MAX_SIZE + "]\n" + "§e小队长:\n§c" + list.get(0) + '\n' + "§e小队玩家:\n§a" + member;
                }
            }
        }
        return null;
    }
}
